package com.dsteiner.xelavos.client;

import java.beans.PropertyChangeListener;

import com.dsteiner.widgets.client.PropertyChangeCollection;
import com.dsteiner.widgets.client.Widgets.ImageExt;
import com.dsteiner.xelavos.client.controller.ChangeableImageController;

public class ChangeableImage extends ImageExt{


	public static class ChangeableImageModel {
		private PropertyChangeCollection propertyChangeSupport = new PropertyChangeCollection(
				this);
	
		public void addPropertyChangeListener(String propertyName,
				PropertyChangeListener listener) {
			propertyChangeSupport.registerPropertyChangeListener(propertyName,
					listener);
		}

		private String url;

		public String getUrl() {
			return url;
		}

		public void setUrl(String url) {
			String oldUrl = this.url;
			this.url = url;
			propertyChangeSupport.firePropertyChange("url", oldUrl, url);
		}
	}
	
	private final ChangeableImageModel changeableImageModel;
	private ChangeableImageController changeableImageController = new ChangeableImageController();
	
	public ChangeableImage(ChangeableImageModel changeableImageModel) {
		this.changeableImageModel = changeableImageModel;
		changeableImageController.registerChangeableImage(this);
		changeableImageController.registerChangeableImageModel(changeableImageModel);
		changeableImageController.updateUrl();
	}
}
